<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Yi extends CI_Controller {


	public function index(){
		exit('hello');
	}

	public function articles(){
		exit('articles');
	}

	public function pics($pageSize=10,$pageIndex=1){
		$result = $this->queryData('PIC',$pageIndex,$pageSize);
		print_r(json_encode($result));exit;
	}

	public function videos($pageSize=10,$pageIndex=1){
		$result = $this->queryData('VIDEO',$pageIndex,$pageSize);
		print_r(json_encode($result));exit;
	}

	public function dgs($pageSize=10,$pageIndex=1){
		$result = $this->queryData('DG',$pageIndex,$pageSize);
		print_r(json_encode($result));exit;
	}

	public function peoples($pageSize=10,$pageIndex=1){
		$result = $this->queryData('PEOPLE',$pageIndex,$pageSize);
		print_r(json_encode($result));exit;
	}

	function queryData($type,$pageIndex,$pageSize){
		$this->load->database();
		$this->db->order_by('id', 'DESC');
		$query = $this->db->get_where('yi_articles', array('type' => $type), $pageSize,($pageIndex-1) * $pageSize)->result_array();

		$count = $this->db->select('title,img_url')
		        ->where('type', $type)
		        ->count_all_results('yi_articles');

		$result = array('list'=>$query,'count'=>$count);
		return $result;
	}

}
